
import { Route, Switch, NavLink, Redirect } from 'react-router-dom'
import { Suspense} from "react"

let RouterView=(props)=>{
   let {RouterList}=props;
   console.log(RouterList);
   let routerlist=RouterList.filter((item,index)=>{
       return !item.to
   })
   let redirect=RouterList.filter((item,index)=>{
    return item.to
   })[0]
   return (
       <Suspense fallback={<div>...loading</div>}>
           <Switch>
                {
                  routerlist &&routerlist.length ?routerlist.map((item,index)=>{
                       return <Route path={item.path} key={index} render={(routerprops)=>{
                             return <item.component {...routerprops} children={item.children}></item.component>
                       }}></Route>
                  }):""
                }
                {
                   redirect? <Redirect from={redirect.from} to={redirect.to}></Redirect>:"暂无路由"
                }
           </Switch>
       </Suspense>
   )
}


export default RouterView